package com.javalong.affairs.module.renwujinzhang.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.javalong.affairs.R;
import com.javalong.affairs.base.adapter.BaseAdapter;
import com.javalong.affairs.base.model.User;

import java.util.ArrayList;
import java.util.List;

public class UserAdapter extends BaseAdapter {
    private List<User> selectedUsers;
    private boolean hasCheck;

    public UserAdapter(Context context, List<User> deptList) {
        this(context, deptList, true);
    }

    public UserAdapter(Context context, List<User> deptList, boolean hasCheck) {
        super(context, deptList);
        selectedUsers = new ArrayList<User>();
        this.hasCheck = hasCheck;
    }

    public List<User> getSelectedUsers() {
        return selectedUsers;
    }

    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
        selectedUsers.clear();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final User user = (User) getItem(position);
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_user, null);
            holder.tv_user = (TextView) convertView.findViewById(R.id.tv_user);
            convertView.setTag(holder);
        }
        holder.tv_user.setText(user.name);
        return convertView;
    }

    class ViewHolder {
        TextView tv_user;
    }

}
